import sys
from time import time
from scanner import syn_scan, connect_scan
from service_detection import grabber


def update(port = None):
	if port != None:
		print ".", port
	else:
		print "."

if __name__ == "__main__":

	if len(sys.argv) < 3 or not sys.argv[2] in ['S', 'C', 'G']:
		print "ejercicio1.py [host] [C/S/G] (C = Connect Scan, S = Syn Scan, G = grabbing)"
		exit()
	
	host = sys.argv[1]
	tipo = sys.argv[2]

	if tipo == 'S':
		(open_ports, filtered) = syn_scan(host, update)
		print "Syn Scan, puertos abiertos: ", open_ports
		print "Puertos filtrados: ", filtered
	elif tipo == 'C':
		open_ports = connect_scan(host, update)
		print "Connect Scan, puertos abiertos: ", open_ports
	elif tipo == 'G':
		res = grabber(host)
		print "Resultados del grabber:"
		print res
	else:
		exit()
		

